package smallchange.oop;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class smallchangeOOP {
    boolean flag = true;
    Scanner scanner = new Scanner(System.in);

    String details = "-------------零钱通明细-------------";
    Date date = null;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

    double money = 0;
    double balance = 0;
    String note = "";

    public void menu(){
        System.out.println("==============零钱通菜单==============");
        System.out.println("\t\t\t1. 零钱通明细");
        System.out.println("\t\t\t2. 收益入账");
        System.out.println("\t\t\t3. 消    费");
        System.out.println("\t\t\t4. 退    出");
    }


    public void detail(){
        System.out.println(details);
    }

    public void income(){

        System.out.print("收益入账:>");
        money = scanner.nextDouble();
        if(money <= 0){
            System.out.println("请输入正确的金额!");
            return;
        }
        balance += money;
        date = new Date();
        details += "\n收益入账\t+" + money + "\t" + sdf.format(date) + "\t余额:" + balance;
        return;
    }

    public void pay(){
        if(balance <= 0 ){
            System.out.println("穷逼,没钱你消费个蛋!");
            return;
        }
        System.out.print("请输入消费金额:>");
        money  = scanner.nextInt();
        if(money <= 0 || money > balance){
            System.out.println("输入错误，金额应在0-" + balance);
            return;
        }
        System.out.print("请输入消费场所:>");
        note = scanner.next();
        balance -= money;
        date = new Date();
        details += "\n" + note + "\t-" + money + "\t" + sdf.format(date) + "\t余额:" + balance;
    }

    public void exit(){
        System.out.println("你确定要退出吗? y/n");
        while (true){
            System.out.print("请选择:>");
            String df = scanner.next();
            if(df.equals("y")){
                System.out.println("程序退出!");
                flag = false;
                break;
            }
            else if(df.equals("n")){
                System.out.println("退回主菜单!");
                break;
            }
            else {
                System.out.println("输入错误,请重新选择!");
            }

        }
        return;
    }
}
